﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace intheweel
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void login_Load(object sender, EventArgs e)
        {
            var bug = "select * from Articles ";
            var xiong = Dbhelper.GetData(bug);
            dataGridView1.DataSource = xiong;
            dataGridView1.ReadOnly = true;
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridView1.AllowUserToAddRows = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var zhu = dataGridView1.SelectedRows[0];
            var chu = zhu.Cells["id"].Value;
            if (chu != null)
            {
                var fu = MessageBox.Show("are you 确定?", "警告", MessageBoxButtons.YesNo);
                if (fu.Equals(DialogResult.Yes))
                {
                    var dda = string.Format("delete  from  Articles where id='{0}'", chu);
                    var li = Dbhelper.Luoxuan(dda);
                    if (li > 0)
                    {
                        var ke = string.Format("select * from Articles where Title like '%{0}%' or Author like '%{1}%'", textBox2.Text, textBox2.Text);
                        var lu = Dbhelper.GetData(ke);
                        dataGridView1.DataSource = lu;
                        MessageBox.Show("删除成功!");
                    }
                }
            }
            else
            {
                MessageBox.Show("未选择任何数据");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            addd addd = new addd();
            var ss = addd.ShowDialog();
            if (ss == DialogResult.Yes)
            {
                var drr = "select * from Articles ";
                var dew = Dbhelper.GetData(drr);
                dataGridView1.DataSource = dew;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            var ke = string.Format("select * from Articles where Title like '%{0}%' or Author like '%{1}%'", textBox2.Text, textBox2.Text);
            var lu = Dbhelper.GetData(ke);
            dataGridView1.DataSource = lu;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                var Title = (string)dataGridView1.SelectedRows[0].Cells["Title"].Value;
                var Author = (string)dataGridView1.SelectedRows[0].Cells["Author"].Value;
                var CreatedTime = (string)dataGridView1.SelectedRows[0].Cells["CreatedTime"].Value;
                var id = (int)dataGridView1.SelectedRows[0].Cells["Id"].Value;
                addd addd = new addd(Title, Author, CreatedTime, id);
                var ce = addd.ShowDialog();
                if (ce == DialogResult.Yes)
                {
                    var fa = "select * from Articles";
                    var dds = Dbhelper.GetData(fa);
                    dataGridView1.DataSource = dds;
                }
            }
            else
            {
                MessageBox.Show("未选择任何一行");
            }
        }
    }
}
